package com.lanhai.zhonglai.hc;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import com.lanhai.zhonglai.interfaces.ISendData; 

@Component
public class HCQueueThread {
	  boolean running;
	  Thread th;
  
	  @Autowired
	  ISendData sendUtils;
 

	public void Start( ) {
		running=true;
		 
		th=new Thread() {
			@Override
			public void run() {
				while (running) {
					HCQueueData data = HCQueue.Pop();
					if (data != null) {
						sendUtils.sendHCData(data.getIp(), data.getPort(), 1, data.getRemark(), data.getData(), data.getStationName());
						try {
							Thread.sleep(500);
						} catch (InterruptedException e) {

						}
					} else {
						try {
							Thread.sleep(1000);
						} catch (InterruptedException e) {

						}
					}
					
				}

			}

		};
		th.start();
	}

 

	public void Stop() {
		running=false;
		try {
			th.interrupt();
			th=null;
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
}
